/*
 * Copyright (C), 2015-2018
 * FileName: AutowireCapableBeanFactory
 * Author:   zhao
 * Date:     2018/11/16 15:25
 * Description: bean工厂具体的实现类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.lizhaoblog.tinyspring.factory;

import com.lizhaoblog.tinyspring.BeanDefinition;

import java.lang.reflect.InvocationTargetException;

/**
 * 〈一句话功能简述〉<br>
 * 〈bean工厂具体的实现类〉
 *
 * @author zhao
 * @date 2018/11/16 15:25
 * @since 1.0.1
 */
public class AutowireCapableBeanFactory extends AbstractBeanFactory {
    @Override
    protected Object doCreateBean(BeanDefinition beanDefinition) {
        try {
            // Java 11
            var bean = beanDefinition.getBeanClass().getDeclaredConstructor().newInstance();
            // Java 8
//            Object bean = beanDefinition.getBeanClass().getDeclaredConstructor().newInstance();
            return bean;
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            e.printStackTrace();
        }
        return null;
    }
}
